package com.shq.ex1;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class MusicSpecialView extends BaseAdapter {

    public Context context;
    GridView gv_1;
    public static MusicSpecialView msv;

    public void disPlaySpecial(GridView gv, Context context) {
        this.context = context;
        msv = new MusicSpecialView();
        this.gv_1 = gv;
        this.gv_1.setAdapter(msv);

    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return Music_infoAdapter.musicList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return Music_infoAdapter.musicList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        LayoutInflater lif = LayoutInflater.from(MusicActivity.context);
        View v = lif.inflate(R.layout.gridspecial_item, null);

        ImageView iv;
        TextView tv1;
        TextView tv2;

        iv = (ImageView) v.findViewById(R.id.gridspecial_view1);
        tv1 = (TextView) v.findViewById(R.id.album_xxx);
        tv2 = (TextView) v.findViewById(R.id.artist_xxx);

        // 获取专辑图片路径
        String url = MusicActivity.music_info
                .getAlbumArt(Music_infoAdapter.musicList.get(position).get_id());
        if (url != null) {
            iv.setImageURI(Uri.parse(url));
        } else {
            iv.setImageResource(R.drawable.default_album);
        }
        iv.setAnimation(AnimationUtils.loadAnimation(
                MusicActivity.context, R.anim.alpha_z));

        // 带动画显示专辑名
        tv1.setText(Music_infoAdapter.musicList.get(position).getMusicAlbum());
        tv1.setAnimation(AnimationUtils.loadAnimation(
                MusicActivity.context, R.anim.alpha_y));

        // 带动画显示歌手名
        tv2.setText(Music_infoAdapter.musicList.get(position).getMusicSinger());
        tv2.setAnimation(AnimationUtils.loadAnimation(
                MusicActivity.context, R.anim.alpha_y));

        return v;
    }

}
